package com.stars.home.vmodel

import android.app.Application
import android.graphics.Color
import android.text.TextUtils
import android.view.View
import androidx.lifecycle.MutableLiveData
import com.stars.home.activity.WayDetailsActivity
import com.stars.home.fragment.AccountBillFragment
import com.stars.home.model.AmountCount
import com.stars.home.model.User
import com.stars.home.utils.net.NetEngine
import com.trailer.base.base.BRRepository
import com.trailer.base.base.BRViewModel
import com.trailer.base.net.IResp
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

/**
 *
 *on 2020/9/18
 */
class CustomerOrderListVModel(application: Application) : BRViewModel<BRRepository>(application) {



    val user: MutableLiveData<User?> = MutableLiveData(User.get())
    var info: MutableLiveData<AmountCount> = MutableLiveData<AmountCount>()

    var fragment: AccountBillFragment? = null
    var order_state:String? = "0"//订单状态


    fun toDetails(order_id:String?){


        UiSwitch.bundle(repository().context, WayDetailsActivity::class.java,
                B().putString("order_id",order_id).ok())


    }

    fun isShowCarName(vehicle_name:String?,username:String):String{
        if(TextUtils.isEmpty(vehicle_name)&&TextUtils.isEmpty(username)){
          return ""
        }
        if(TextUtils.isEmpty(vehicle_name)){
            return ""
        }
        if(TextUtils.isEmpty(username)){
            return ""+vehicle_name
        }
        return "$vehicle_name ($username)"

    }


    fun showButTips(state:Int):String{
        if(state==-1){
            return "待支付"
        }
        if(state==0){
            return "已取消"
        }
        if(state==1){
            return "待接单"
        }
        if(state==6){
            return "已完成"
        }
        return "进行中"

    }

    fun getButTipsColor(state:Int):Int{

        if(state==6||state==0){
            return Color.parseColor("#999999")
        }
        return Color.parseColor("#FF5036")
    }

    fun isShowChat(state:Int,type:Int):Int{

        if(state==-1||state==0||state==1||state==6){
            return View.GONE
        }
        if(type==1||type==2||type==3){
            return View.GONE
        }
        return View.VISIBLE
    }
    fun isShowPhone(state:Int):Int{

        if(state==-1||state==0||state==1||state==6){
            return View.GONE
        }
        return View.VISIBLE
    }

    override fun apiFunc(): suspend () -> IResp<*> {


        return { NetEngine.service.orderList(order_state, "10", repository().page)
        }
    }
}
